﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
public partial class Form_DangNhap : System.Web.UI.Page
{
    GetData getData;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("QuenMatKhau.aspx");
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect("DangKy.aspx");
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (txtTenDangNhap.Text == "Admin" && txtMatKhau.Text == "Admin")
        {
            Session["UserLogin"] = "Admin";
            Session["MaKh"] = "100";
            Response.Redirect("Admin.aspx");
        }
        else
        {
            getData = new GetData();
            KhachHang kh = new KhachHang();
            mahoavb.Mahoa mh = new mahoavb.Mahoa();
            string _Pass = mh.Encode(txtMatKhau.Text.Trim(), 9);
            kh = getData.Login(txtTenDangNhap.Text.Trim(), _Pass);
            if (kh != null)
            {
                Session["MaKh"] = kh.MaKH;
                Session["UserLogin"] = kh.TenKH;
                Response.Redirect("TrangChu.aspx");
            }
            else
            {
                lblDangNhapLoi.Text = "Tên đăng nhập hoặc mật khẩu không đúng.";
                txtMatKhau.Text = "";
                txtTenDangNhap.Text = "";
            }
        }
    }
}